﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PointShop.ShopSystem;
using ReLogic.Content;
using System;
using Terraria;
using Terraria.ModLoader;
using 积分商店扩展.Common.ModUtils;

namespace 积分商店扩展.Common.Systems.BiomeRegister
{
    public class CalamityBiome : ModSystem
    {
        public override void Load()
        {
            string[] abyssBiomeTypeNames;
            if (ModLoader.TryGetMod("CalamityMod", out Mod calamityMod))
            {
                abyssBiomeTypeNames = ["CalamityMod.BiomeManagers.AbyssLayer1Biome", "CalamityMod.BiomeManagers.AbyssLayer2Biome", "CalamityMod.BiomeManagers.AbyssLayer3Biome", "CalamityMod.BiomeManagers.AbyssLayer4Biome"];
                Func<Player, bool> biomeActiveCondition;
                biomeActiveCondition = MyUtils.GetBiomeActiveCondition(calamityMod, "CalamityMod.BiomeManagers.SunkenSeaBiome", "IsBiomeActive");
                PointShopSystem.RegisterGameEnvironment(Mod, ModContent.Request<Texture2D>("积分商店扩展/Assets/Textures/BiomeIcon/CalamityMod/SunkenSeaIcon", (AssetRequestMode)2), "SunkenSea", biomeActiveCondition, 0, new Color(36, 61, 111), 0);
                Func<Player, bool> biomeActiveCondition2;
                biomeActiveCondition2 = MyUtils.GetBiomeActiveCondition(calamityMod, "CalamityMod.BiomeManagers.SulphurousSeaBiome", "IsBiomeActive");
                PointShopSystem.RegisterGameEnvironment(Mod, ModContent.Request<Texture2D>("积分商店扩展/Assets/Textures/BiomeIcon/CalamityMod/SulphurousSeaIcon", (AssetRequestMode)2), "SulphurousSea", biomeActiveCondition2, 0, new Color(62, 217, 145), 0);
                PointShopSystem.RegisterGameEnvironment(Mod, ModContent.Request<Texture2D>("积分商店扩展/Assets/Textures/BiomeIcon/CalamityMod/AbyssLayer4Icon", (AssetRequestMode)2), "Abyss", AbyssCondition, 0, new Color(54, 64, 89), 0);
                Func<Player, bool> biomeActiveCondition3;
                biomeActiveCondition3 = MyUtils.GetBiomeActiveCondition(calamityMod, "CalamityMod.BiomeManagers.BrimstoneCragsBiome", "IsBiomeActive");
                PointShopSystem.RegisterGameEnvironment(Mod, ModContent.Request<Texture2D>("积分商店扩展/Assets/Textures/BiomeIcon/CalamityMod/BrimstoneCragsIcon", (AssetRequestMode)2), "BrimstoneCrags", biomeActiveCondition3, 0, new Color(224, 99, 78), 0);
                Func<Player, bool> biomeActiveCondition4;
                biomeActiveCondition4 = MyUtils.GetBiomeActiveCondition(calamityMod, "CalamityMod.BiomeManagers.AstralInfectionBiome", "IsBiomeActive");
                PointShopSystem.RegisterGameEnvironment(Mod, ModContent.Request<Texture2D>("积分商店扩展/Assets/Textures/BiomeIcon/CalamityMod/AbovegroundAstralBiomeIcon", (AssetRequestMode)2), "AstralInfection", biomeActiveCondition4, 0, new Color(77, 59, 97), 0);
            }
            bool AbyssCondition(Player player)
            {
                string[] array;
                array = abyssBiomeTypeNames;
                for (int i = 0; i < array.Length; i++)
                {
                    if (MyUtils.GetBiomeActiveCondition(biomeTypeName: array[i], mod: calamityMod, methodName: "IsBiomeActive")(player))
                    {
                        return true;
                    }
                }
                return false;
            }
        }
    }
}
